<?php
require '../util/Classes/PHPExcel.php';
include_once("../service/newsletterService.php");

$objPHPExcel = new PHPExcel();
        
$objPHPExcel->getActiveSheet()->setTitle('Data');	
$rowNumber = 1;
$newsletters = findAllNewsletters();

while ($row = mysql_fetch_row($newsletters)) {
	$col = 'A';
	foreach($row as $cell) {
		$objPHPExcel->getActiveSheet()->setCellValue($col.$rowNumber,$cell);
        $col++;
	}
	$rowNumber++;
}

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
ob_end_clean();

header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="Danh sach email.xlsx"');

$objWriter->save('php://output');
$objPHPExcel->disconnectWorksheets();
unset($objPHPExcel);
?>